home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / imengv3.41p2.lha / ImEngV3.41p2 / Extra / DOpus5 / arexx / IE_BatchProcess.dopus5 next >
Text File  |  1996-09-15  |  11KB  |  366 lines

  1. /*
  2. ** $VER: IE_BatchProcess.dopus5 1.21 (2/9 Stockholm/Sweden)
  3. ** Copyright © 1996 by Patrik M Nydensten 
  4. **
  5. ** Processes all selected image files in the SRCE directory and
  6. ** saves them into DEST directory. Uses IE Batch scripts.
  7. ** Requires Image Engineer 3.0 or higher and DOpus 5.0 or higher.
  8. ** Call: (AREXX) DOpus5:arexx/IE_BatchProcess.dopus5 {Qp}
  9. */
  10.  
  11. CFG_BATCH_DIR = 'IE:Arexx/Batch/'
  12. CFG_IE_PRIORITY = '-3'
  13.  
  14. options results
  15. signal on syntax
  16.  
  17. lf='0a'x ; dq='22'x ; sq='27'x
  18. old_ie_pri = '0'
  19.  
  20. parse arg portname
  21. if left(portname,5)='DOPUS' then address value portname
  22. else exit
  23.  
  24. if ~show(ports,'IMAGEENGINEER') then do
  25.      dopus request '"Could not locate IE'sq's arexx port!" OK'
  26.   exit                 
  27. end                 
  28.  
  29. /* Get info from DOpus */
  30.  
  31. lister query source                /* get source handler */
  32. parse var result handle nil
  33. if (RC~= 0) then exit
  34.  
  35. lister query dest                  /* get destination handler */
  36. parse var result dhandle nil
  37. if (RC~= 0) then do
  38.   dopus request '"No DEST directory selected." Use SOURCE dir|Cancel'
  39.   if (RC=1) then dhandle = handle
  40.   else exit
  41. end
  42.  
  43. lister query handle path           /* get current source path */
  44. src_path = strip(result,B,'"')
  45.  
  46. lister query dhandle path           /* get current dest path */
  47. dst_path = strip(result,B,'"')
  48.  
  49. lister query handle selfiles ':'   /* get selected file names */
  50. sel_files = result
  51.  
  52. lister query handle numselfiles    /* get number of selected files */
  53. num_files = result
  54. if num_files = 0 then exit
  55.  
  56. if num_files = 1 then do  /* Ask for cloning of single image */
  57.   dopus request '"You have only selected one single image.'lf||,
  58.             'Would you like to clone it?" Yes, clone|No, single'
  59.   if (rc = 1) then do
  60.     do while ~datatype(cnumber,'N')
  61.       dopus getstring '"Set number of clone images."' '4' '"10"' 'Clone'
  62.       cnumber = result
  63.  
  64.       if ~datatype(cnumber,'N') then do
  65.         dopus request '"Bad number, try again!" I'sq'll try'
  66.       end
  67.     end /* end while */
  68.     num_files = cnumber ; clone_image = sel_files
  69.   end /* do clone ? */
  70. end
  71.  
  72. /* Get batch script and check it  -------------------------------------- */
  73.  
  74. lister new CFG_BATCH_DIR
  75. bhandle = result
  76.  
  77. lister wait bhandle
  78. lister set bhandle source
  79. command none
  80. lister set bhandle show '(#?.ieb)'
  81. lister set bhandle title 'Select IE batch script.'
  82. lister refresh bhandle 'full'
  83. lister wait bhandle
  84.  
  85. do forever   /* get batch script */
  86.   address COMMAND 'wait'
  87.   lister query bhandle numselfiles
  88.   if result = 1 then do
  89.     lister query bhandle selfiles
  90.     parse var result bscript nil
  91.     bscript = CFG_BATCH_DIR||strip(bscript,B,'"')
  92.     leave
  93.   end
  94.   lister query source
  95.   if result ~= bhandle then do
  96.     lister close bhandle
  97.     dopus request '"User aborted action!" OK'
  98.     exit
  99.   end
  100. end
  101.  
  102. lister close bhandle
  103.  
  104. if ~exists(bscript) then do  
  105.   dopus request '"Unable to find IE batch script!" OK'
  106.   exit
  107. end
  108. else do
  109.   binfo = bei('INFO')  /* get extra info from batch */ 
  110.   if word(binfo,1) ~= 'OK' then do
  111.     dopus request '"Unable to access IE batch script!" OK'
  112.     exit
  113.   end
  114. end
  115. nil = info_add_setup(binfo)  /* setup optional extra info for batch */
  116.  
  117. /* Get config(s) from batch script  ------------------------------------ */
  118.  
  119. if num_files > 1 then do
  120.   dopus request '"Select settings for first image." Continue'
  121.   bopt_f = bei('CONFIG') ; dopus front
  122.   dopus request '"Select new settings for last image?" Yes, new|No, use same'
  123.   if (rc = 0) then bopt_l = bopt_f
  124.   else do
  125.     dopus request '"Select settings for last image." Continue'
  126.     bopt_l = bei('CONFIG' sq'"'bopt_f'"'sq) ; dopus front
  127.     dopus request '"Select settings calculation mode." Linear|Spline'
  128.     calc_type = rc
  129.     if calc_type ~= 1 then nil = add_mathlib()
  130.   end
  131. end
  132. else do
  133.   bopt_f = bei('CONFIG') ; dopus front
  134.   bopt_l = bopt_f
  135. end
  136.  
  137. dopus getstring '"Enter output filename." 25 "Output" Go!'
  138. dst_filename = result
  139.  
  140. /* Start processing  --------------------------------------------------- */
  141.  
  142. address 'IMAGEENGINEER' 'PRIORITY_SET' CFG_IE_PRIORITY
  143. old_ie_pri = result
  144.  
  145. address value portname
  146. dopus front
  147.  
  148. lister set handle progress num_files 'Processing images...'
  149.  
  150. do i = 1 to num_files  /* Process loop */
  151.  
  152.   address value portname
  153.  
  154.   parse var sel_files image_file ':' sel_files
  155.   if clone_image ~= 'CLONE_IMAGE' then image_file = clone_image
  156.   image_file = strip(image_file,B,'"')
  157.  
  158.   lister set handle progress name image_file  /* update progress display */
  159.   lister query handle abort                   /* check if aborted */
  160.   if result then do
  161.     lister clear handle progress  /* exit progress display mode */
  162.     lister refresh handle 'full'
  163.     lister refresh dhandle 'full'
  164.     lister read dhandle '"'||dst_path||'"' force
  165.     address 'IMAGEENGINEER' 'PRIORITY_SET' old_ie_pri
  166.     dopus front
  167.     dopus request '"User aborted..." OK'
  168.     lister clear handle abort
  169.     exit
  170.   end
  171.  
  172.   bei_proc = 'PROCESS' sq'"'src_path||image_file'"'sq sq'"'dst_path||dst_filename||'.'||right(i,4,'0')'"'sq sq'"'calc_bopt(i)'"'sq get_info_add()
  173.   say bei_proc
  174.   nil = bei(bei_proc)
  175.  
  176.   lister select handle '"'||image_file||'"' 0  /* unselect processed file */
  177.   lister set handle progress count i           /* update progress display */
  178.   lister refresh handle full                   /* update lister display   */
  179.   lister refresh dhandle full                  /* update lister display   */
  180.  
  181. end  /* end of process loop */
  182.  
  183. lister clear handle progress        /* exits progress display mode */
  184. lister refresh handle 'full'        /* update source */
  185. lister refresh dhandle 'full'       /* update dest */
  186. lister read dhandle '"'||dst_path||'"' force
  187.  
  188. address 'IMAGEENGINEER' 'PRIORITY_SET' old_ie_pri
  189.  
  190. dopus front
  191.  
  192. exit
  193.  
  194. /* Procedures  ------------------------------------------------------*/
  195.  
  196. BEI:  /* Batch script caller */
  197.   parse arg bei_input
  198.  
  199.   interpret call '"'bscript'"' bei_input
  200.   bei_output = result
  201.  
  202.   say bei_output        
  203.  
  204.   address(portname)
  205. return bei_output
  206.  
  207. /* Config settings twiner  ---------------------------------------- */
  208.  
  209. Calc_bopt:
  210.   parse arg cur_filenum
  211.   calc_output = ''
  212.   bopt_fx = bopt_f ; bopt_lx = bopt_l
  213.   if (bopt_fx = bopt_lx) then calc_output = bopt_fx
  214.   else do forever
  215.     parse var bopt_fx val_fx bopt_fx 
  216.     parse var bopt_lx val_lx bopt_lx 
  217.     val_fx = strip(val_fx) ; val_lx = strip(val_lx)
  218.     if ((val_fx='')|(val_lx='')) then leave
  219.     if ((left(val_fx,1)='#')|(left(val_lx,1)='#')) then calc_output = calc_output val_fx
  220.     else do   /* do linear/spline calculation */
  221.       select
  222.         when calc_type = 1 then calc_output = calc_output trunc( (val_fx+(val_lx - val_fx)*(cur_filenum-1)/(num_files-1)) )
  223.         when calc_type = 0 then calc_output = calc_output trunc( val_lx-(((cos(3.14159265*(cur_filenum-1)/(num_files-1))+1)/2)*(val_lx-val_fx)) )
  224.         otherwise nop
  225.       end /* select */
  226.     end  /* do calc */
  227.   end
  228. return strip(calc_output)
  229.  
  230. add_mathlib:
  231.   if ~show(L,'rexxmathlib.library') then do
  232.     if exists('LIBS:rexxmathlib.library') then do
  233.       if ~addlib('rexxmathlib.library',0,-30,0) then do
  234.         dopus request '"Failed to load libs:rexxmathlib.library!" OK'
  235.       end
  236.     end /* lib found on disk */
  237.     else do
  238.       dopus request '"Failed to find libs:rexxmathlib.library!" OK'
  239.     end
  240.   end /* lib exists in mem */
  241. return 'OK'
  242.  
  243. /* Output optional extra info if necessary  ---------------------------- */
  244.  
  245. get_info_add:
  246.   info_output = ''
  247.  
  248.   if pos('S',add_input)~=0 then do
  249.     if sec_force = 1 then info_output = sq'"'sec_path||strip(sec_filelist,B,'"')'"'sq
  250.     else do
  251.       parse var sec_filelist file ':' sec_filelist
  252.       info_output = sq'"'sec_path||strip(file,B,'"')'"'sq
  253.     end
  254.   end
  255.   if pos('A',add_input)~=0 then do
  256.     if alp_force = 1 then info_output = info_output sq'"'alp_path||strip(alp_filelist,B,'"')'"'sq
  257.     else do
  258.       parse var alp_filelist file ':' alp_filelist
  259.       info_output = info_output sq'"'alp_path||strip(file,B,'"')'"'sq
  260.     end
  261.   end
  262.   if pos('F',add_input)~=0 then do
  263.     info_output = info_output sq'"'i':'num_files'"'sq
  264.   end
  265.  
  266. return strip(info_output)
  267.  
  268. info_add_setup:
  269.   parse arg add_input
  270.  
  271. /* Retrieve Secondary/Alpha image(s)  ---------------------------------- */ 
  272.  
  273.   if pos('S',add_input)~=0 then do
  274.     if substr(add_input,pos('S',add_input)+1,1) = '1' then sec_files = 1
  275.     else sec_files = num_files
  276.  
  277.     if sec_files > 1 then do  /* select multifile */
  278.       dopus request '"This Batch script requires that you select'lf,
  279.                       sec_files 'SECONDARY images." Continue|Force single'
  280.       if rc = 0 then do
  281.         sec_files = 1 ; sec_force = 1
  282.       end
  283.     end
  284.     else do  /* select single file */
  285.       dopus request '"This Batch script requires that you select'lf,
  286.                       'one SECONDARY image." Continue'
  287.     end
  288.  
  289.     lister new src_path
  290.     bhandle = result
  291.     
  292.     lister wait bhandle
  293.     lister set bhandle source
  294.     command none
  295.     lister set bhandle title 'Select' sec_files 'SECONDARY image(s).'
  296.     lister refresh bhandle 'full'
  297.     lister wait bhandle
  298.     
  299.     do forever   /* get batch script */
  300.       address COMMAND 'wait'
  301.       lister query bhandle numselfiles
  302.       if result = sec_files then do
  303.         lister query bhandle selfiles ':'
  304.         parse var result sec_filelist
  305.         leave
  306.       end
  307.     end
  308.     lister query bhandle path
  309.     sec_path = strip(result,'B','"')
  310.     lister close bhandle
  311.   end  /* end of get SEC */
  312.  
  313.   if pos('A',add_input)~=0 then do
  314.     if substr(add_input,pos('A',add_input)+1,1) = '1' then alp_files = 1
  315.     else alp_files = num_files
  316.  
  317.     if alp_files > 1 then do  /* select multifile */
  318.       dopus request '"This Batch script requires that you select'lf,
  319.                       alp_files 'ALPHA images." Continue|Force single'
  320.       if rc = 0 then do
  321.         alp_files = 1 ; alp_force = 1
  322.       end
  323.     end
  324.     else do  /* select single file */
  325.       dopus request '"This Batch script requires that you select'lf,
  326.                       'one ALPHA image." Continue'
  327.     end
  328.  
  329.     lister new src_path
  330.     bhandle = result
  331.     
  332.     lister wait bhandle
  333.     lister set bhandle source
  334.     command none
  335.     lister set bhandle title 'Select' alp_files 'ALPHA image(s).'
  336.     lister refresh bhandle 'full'
  337.     lister wait bhandle
  338.  
  339.     do forever   /* get batch script */
  340.       address COMMAND 'wait'
  341.       lister query bhandle numselfiles
  342.       if result = alp_files then do
  343.         lister query bhandle selfiles ':'
  344.         parse var result alp_filelist
  345.         leave
  346.       end
  347.     end
  348.     lister query bhandle path
  349.     alp_path = strip(result,'B','"')
  350.     lister close bhandle
  351.   end  /* end of get ALP */
  352.  
  353. return 'OK'
  354.  
  355. Syntax:
  356.   syntax_rc = rc
  357.   lister clear handle progress        /* exits progress display mode */
  358.   lister refresh handle 'full'        /* update source */
  359.   lister refresh dhandle 'full'       /* update dest */
  360.   lister read dhandle '"'||dst_path||'"' force
  361.   address 'IMAGEENGINEER' 'PRIORITY_SET' old_ie_pri
  362.   dopus front
  363.   dopus request '"Internal error on line' SIGL || lf || 'Error:' syntax_rc errortext(syntax_rc) '" OK'
  364.   exit
  365. return 0
  366.